

using System;

using Mono.Cecil.Metadata;
using Mono.Collections.Generic;
using System.Diagnostics;

namespace Mono.Cecil
{


    [DebuggerDisplay("{FullName}")]
    public class TypeReferenceRuntime : TypeReference
    {

        private TypeDefinition _sealedType;
        private TypeReference _base;

        internal TypeReferenceRuntime(TypeReference typeReference, TypeDefinition sealedType)
        {
            this._base = typeReference;
            this._sealedType = sealedType;
        }


        public override string Name
        {
            get { return _base.Name; }
            set
            {
                _base.Name = value;
            }
        }

        public override string Namespace
        {
            get { return _base.Namespace; }
            set
            {
                _base.Namespace = value;
            }
        }

        public override bool IsValueType
        {
            get { return _base.IsValueType; }
            set { _base.IsValueType = value; }
        }

        public override ModuleDefinition Module { get { return _base.Module; } }

        public IGenericParameterProvider Type { get { return this; } }

        public IGenericParameterProvider Method { get { return null; } }

        public GenericParameterType GenericParameterType { get { return GenericParameterType.Type; } }

        public override bool HasGenericParameters { get { return _base.HasGenericParameters; } }

        public override Collection<GenericParameter> GenericParameters
        { get { return _base.GenericParameters; } }

        public override IMetadataScope Scope { get { return _base.Scope; } }

        public override bool IsNested { get { return this.DeclaringType != null; } }

        public override TypeReference DeclaringType
        {
            get { return _base.DeclaringType; }
            set { _base.DeclaringType = value; }
        }

        public override string FullName { get { return _base.FullName; } }

        public override bool IsPrimitive { get { return _base.IsPrimitive; } }


        public override MetadataType MetadataType
        {
            get
            {
                return _base.MetadataType;
            }

        }


        public override TypeReference GetElementType()
        {
            return this;
        }

        public virtual TypeDefinition Resolve()
        {
            return new TypeDefinitionRuntime(_base.Resolve(), _sealedType);
        }


        public override System.Reflection.MemberTypes MemberType
        {
            get { return System.Reflection.MemberTypes.TypeInfo; }
        }


        public override int GetHashCode()
        {
            int r = this.Module.Assembly.Name.Name.GetHashCode();
            return r;
        }

        public override bool Equals(object obj)
        {
            bool r = base.Equals(obj);

            if (!r)
            {
                TypeReference Ref = obj as TypeReference;
                if (Ref != null)
                {

                    if (Ref.FullName == this.FullName)
                    {
                        r = (Ref.Module.Assembly.Name.Name == this.Module.Assembly.Name.Name);
                    }

                }
            }

            return r;

        }



        public override string AssemblyQualifiedName
        {

            get
            {
                return _base.AssemblyQualifiedName;
            }
        }


    }

}